package com.freejava.test_thymeleaf.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.lang.reflect.Array;
import java.util.*;

@Controller
public class BuiltinParamController {

    @GetMapping("/builtin_objects")
    public String displayBuiltinParams(Model m) {
        return "builtin_params";
    }

    @GetMapping("/tool_objects")
    public String displayToolObjects(Model m) {
        // 日期类型数据
        Date today = new Date();
        m.addAttribute("today", today);
        // calendars类型
        Calendar calendar = Calendar.getInstance();

        calendar.set(Calendar.YEAR, 2021);
        calendar.set(Calendar.MONTH, 3);
        calendar.set(Calendar.DAY_OF_MONTH, 16);

        m.addAttribute("great_day", calendar);
        // 字符串
        String cannonWord = "Spring Boot like a silver bomb";
        m.addAttribute("chill_word", cannonWord);
        // 数组
        String[] heroArr = new String[3]; // 定义一个字符串类型的数组
        heroArr[0] = "诸葛亮";
        heroArr[1] = "曹操";
        heroArr[2] = "刘备";

        m.addAttribute("hero_array", heroArr);

        // List类型
        List<Integer> goodYears = new ArrayList<>(Arrays.asList(2020, 2021, 2022));

        m.addAttribute("good_years", goodYears);
        // Map类型
        HashMap<String, String> cityMap = new HashMap<>();
        cityMap.put("Sichuan", "Chengdu");
        cityMap.put("hehan", "Zhenzhou");

        m.addAttribute("city_map", cityMap);
        
        return "tool_objects";
    }
}
